<template>
  <el-card>
    <el-form :inline="true">
      <el-form-item label="一级分类">
        <el-select
          v-model="categoryStore.C1Id"
          @change="C1Change"
          :disabled="scence == 1 ? true : false"
        >
          <el-option
            v-for="item in categoryStore.category1Data"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          v-model="categoryStore.C2Id"
          @change="C2Change"
          :disabled="scence == 1 ? true : false"
        >
          <el-option
            v-for="item in categoryStore.category2Data"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select
          v-model="categoryStore.C3Id"
          :disabled="scence == 1 ? true : false"
        >
          <el-option
            v-for="item in categoryStore.category3Data"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
//引入生命周期函数
import { onMounted } from 'vue'
//引入分类仓库
import useCategoryStore from '@/store/modules/category'
//使用分类仓库
const categoryStore = useCategoryStore()
//组件加载完毕调用获取分类方法
onMounted(() => {
  categoryStore.getCategory1()
})
//C1下拉改变事件回调
const C1Change = () => {
  categoryStore.getCategory2()
}
//C2下拉改变事件回调
const C2Change = () => {
  categoryStore.getCategory3()
}
//获取父组件传来的开关
defineProps(['scence'])
</script>

<style scoped></style>
